#include "movetool.h"


MoveTool::MoveTool(QWidget *parent) : QWidget(parent)
{

}

MoveTool::MoveTool(const QJsonObject &functionDetails, QWidget *parent)
    : QWidget(parent)
{

}

MoveTool::MoveTool(const QString &Name, const QJsonObject &functionDetails, QWidget *parent)
    : QWidget(parent)
{
    QGroupBox *groupBox = new QGroupBox(this);
    groupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    // groupBox->setContentsMargins(100, 100, 100, 100);
     // 调用 createMoveTool 进行初始化
    createMoveTool(groupBox, functionDetails);

    // 创建 QVBoxLayout 并设置到当前 QWidget
    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->setContentsMargins(0, 0, 0, 0); // 可选，去除边距
    layout->addWidget(groupBox); // 将 groupBox 添加到布局

    // 让 MoveJoint 使用这个布局
    setLayout(layout);
}
/**********************************************
* @file       mainwindow.cpp
* @brief      MoveTool窗口，分为toolControl窗口和 TCP坐标系按钮窗口
* @author     yfk
* @date       2025-02-11
**********************************************/
void MoveTool::createMoveTool(QGroupBox *groupBox, const QJsonObject &functionDetails)
{
    QHBoxLayout *mainLayout = new QHBoxLayout();

    mainLayout->setContentsMargins(0, 0, 0, 0); // 可选，去除边距

    groupBox->setLayout(mainLayout);

    // 创建用于放置按钮控件的窗口
    QGroupBox *ToolPtnWidget = new QGroupBox("Move Tool",groupBox);

    QVBoxLayout *ToolPtnLayout = new QVBoxLayout(ToolPtnWidget);

    ToolPtnWidget->setLayout(ToolPtnLayout);

    ToolPtnLayout->setContentsMargins(5, 5, 5, 5); // 可选，去除边距

    // 设置 ToolPtnWidget 的缩放策略为 Expanding
    ToolPtnWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);


    // 创建toolControl 按钮
    ToolPushButton *toolControl = new ToolPushButton(groupBox);

    ToolPtnLayout->addWidget(toolControl);

    // 创建用于放置TCP坐标系按钮的窗口
    QGroupBox *TcpWidget = new QGroupBox("TCP",groupBox);

    QVBoxLayout *TcpLayout = new QVBoxLayout(TcpWidget);

    TcpWidget->setLayout(TcpLayout);

    TcpLayout->setContentsMargins(5, 5, 5, 5); // 可选，去除边距

    //TcpWidget->setFixedWidth(300);  // 将按钮窗口的宽度设为 100 像素

    tool_tcp *toolLocation = new tool_tcp(groupBox);

    toolLocation->initializeWithData(functionDetails);

    TcpLayout->addWidget(toolLocation);

    // 设置 TcpWidget 的缩放策略为 Expanding
    TcpWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);


    mainLayout->addWidget(ToolPtnWidget);        // 放置按钮控件的窗口
    mainLayout->addWidget(TcpWidget);    // 放置TCP坐标系按钮的窗口

    // 设置缩放比例
    mainLayout->setStretchFactor(ToolPtnWidget,2);  // ToolPtnWidget 占据 2 份
    mainLayout->setStretchFactor(TcpWidget,1);      // TcpWidget 占据 1 份
}
